-- Off cooldown check
function ccrSpellIsOnCooldown(spell)
	local start, duration, enable = GetSpellCooldown(spell)
	if start ~= nil
	and start == 0
	then
		return false
	else
		return true
	end
end
function SpellIsOnCooldown(spell)
	return ccrSpellIsOnCooldown(spell)
end
function onCD(spell)
	return ccrSpellIsOnCooldown(spell)
end

function SpellCDDuration(spell)
	local start, duration, enable = GetSpellCooldown(spell)
	if start ~= nil and duration ~= nil then
		return (start + duration - GetTime())
	else
		return nil
	end
end

-- Resource for spell check
function ccrSpellIsUsable(spell)
	local isUsable, notEnoughMana = IsUsableSpell(spell)	
	if isUsable == 1
	and notEnoughMana == nil
	then
		return true
	else
		return false
	end
end
function SpellIsUsable(spell)
	return ccrSpellIsUsable(spell)
end

function SIU(spell)
	return ccrSpellIsUsable(spell)
end

-- general spell checks
function ccrSpellIsReady(spell)
	if not ccrSpellIsOnCooldown(spell)
	and ccrSpellIsUsable(spell)
	then
		return true
	else
		return false
	end
end
function SpellIsReady(spell)
	return ccrSpellIsReady(spell)
end
function SIR(spell)
	return ccrSpellIsReady(spell)
end

-- Use for attack cast checks
function ccrSpellCanAttack(spell, unit)
	if unit == nil then unit = "target" end;
	if ccrSpellIsReady(spell)
	and ccrInRange(spell, unit)
	and not ccrPlayerIsCastingOrChanneling() -- is this causing problems?
	then
		return true
	else
		return false
	end
end
function SpellCanAttack(spell, unit)
	return ccrSpellCanAttack(spell, unit)
end
function SCA(spell, unit)
	return SpellCanAttack(spell, unit)
end

function StopIfCasting(spell, leftoncast)
	if spell ~= nil and leftoncast == nil
	and ccrPlayerIsCastingSpell(spell) or ccrPlayerIsChannelingSpell(spell)
	then
		SpellStopCasting()
	end
	if spell ~= nil and leftoncast ~= nil then
		if (ccrPlayerIsCastingSpell(spell) and not ccrPlayerHasLeftOnCast(leftoncast)
		or ccrPlayerIsChannelingSpell(spell) and not ccrPlayerHasLeftOnChannel(leftoncast))
		then
			SpellStopCasting()
		end
	end

end

function ccrSpellIDtoSpellName(spellid)
	local vSpell = GetSpellInfo(spellid)
	if vSpell ~= nil then
		return vSpell
	end
end
